import * as THREE from "three";
import camera from "./camera";
import renderer from "./renderer";
import controls from "./controls";
import scene from "./scene";
import mitt from "@/utils/mitt";
import monitor from "./mesh/monitor";

// import CannonDebugger from 'cannon-es-debugger'
import world from "./CANNON";
// const cannonDebugger = new CannonDebugger(scene, world, {})
const clock1 = new THREE.Clock();
const clock2 = new THREE.Clock();
function animate (t) {
  controls.update();
  //物理引擎
  // cannonDebugger.update()
  const time1 = clock1.getElapsedTime();
  const time2 = clock2.getDelta();
  world.step(1 / 120, time2);
  mitt.emit('time', time1)
  requestAnimationFrame(animate);
  // 使用渲染器渲染相机看这个场景的内容渲染出来
  renderer.render(scene, camera);
  monitor.renderer && monitor.renderer.render(scene, camera);
}

export default animate;
